//
//  AnalystHistoryCell.m
//  RedManStock
//
//  Created by lanou3g on 15/7/22.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "AnalystHistoryCell.h"

@implementation AnalystHistoryCell


- (void)setAnalyst:(Analyst *)analyst{
    if (_analyst!=analyst) {
        _analyst=analyst;
    }
    if (self.stockRedLabel==nil) {
        self.stockRedLabel=[[UILabel alloc]initWithFrame:CGRectMake(221, 10, 58, 21)];
        [self addSubview:self.stockRedLabel];
    }
    if (self.stockYieldLabel==nil) {
        self.stockYieldLabel=[[UILabel alloc]initWithFrame:CGRectMake(296, 10, 50, 21)];
        [self addSubview:self.stockYieldLabel];
    }
    self.dateLabel.text=analyst.viewPointSB.dateSB;
    self.dateLabel.font=[UIFont systemFontOfSize:13];
    self.stockNameLabel.text=analyst.viewPointSB.stockSB.name;
    self.stockYieldLabel.font=[UIFont systemFontOfSize:15];
    self.stockYieldLabel.text=analyst.viewPointSB.stockSB.yield;
    self.stockYieldLabel.font=[UIFont systemFontOfSize:13];
    
    self.stockRedLabel.backgroundColor=[UIColor colorWithRed:0.919 green:0.031 blue:0.140 alpha:1.000];
    float widFloat=[analyst.viewPointSB.stockSB.yield floatValue];
    if (widFloat==0.0f) {
        self.stockRedLabel.backgroundColor=[UIColor clearColor];
        self.stockYieldLabel.textColor=[UIColor blackColor];
        self.stockRedLabel.hidden=YES;
        self.stockYieldLabel.frame=CGRectMake(self.stockRedLabel.frame.origin.x, self.stockYieldLabel.frame.origin.y, self.stockYieldLabel.frame.size.width, self.stockYieldLabel.frame.size.height);
        self.stockYieldLabel.text=@"0.00%";
        
    }
    else{
        self.stockRedLabel.hidden=NO;
        self.stockRedLabel.backgroundColor=[UIColor colorWithRed:0.919 green:0.031 blue:0.140 alpha:1.000];
        self.stockYieldLabel.textColor=[UIColor redColor];
        self.stockRedLabel.frame=CGRectMake(self.stockRedLabel.frame.origin.x, self.stockRedLabel.frame.origin.y, widFloat*1.4f, self.stockRedLabel.frame.size.height);
        
        //当红条长度大于70的时候，右边的周荐股涨幅label放到红条里面，并改成白色
        if (self.stockRedLabel.frame.size.width>70) {
            self.stockYieldLabel.frame=CGRectMake(self.stockRedLabel.frame.origin.x+self.stockRedLabel.frame.size.width-self.stockYieldLabel.frame.size.width, self.stockYieldLabel.frame.origin.y, self.stockYieldLabel.frame.size.width, self.stockYieldLabel.frame.size.height);
            self.stockYieldLabel.textColor=[UIColor whiteColor];
        }
        else{
            self.stockYieldLabel.frame=CGRectMake(self.stockRedLabel.frame.origin.x+self.stockRedLabel.frame.size.width+10, 10, self.stockYieldLabel.frame.size.width, self.stockYieldLabel.frame.size.height);
        }
    }
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
